import pandas as pd

SEQ = "MELLILKANAITTILTAVTFCFASGQNITEEFYQSTCSAVSKGYLSALRTGWYTSVITIELSNIKKNKCNGTDAKIKLIKQELDKYKNAVTELQLLMQSTPATNNQARGSGSGRSLGGGGGGGGGGGGGGGGGGGGGGGFLLGVGSAIASGVAVSKVLHLEGEVNKIKSALLSTNKAVVSLSNGVSVLTSKVLDLKNYIDKQLLPIVNKQSCSISNIETVIEFQQKNNRLLEITREFSVNAGVTTPVSTYMLTNSELLSLINDMPITNDQKKLMSNNVQIVRQQSYSIMSIIKEEVLAYVVQLPLYGVIDTPCWKLHTSPLCTTNTKEGSNICLTRTDRGWYCDNAGSVSFFPQAETCKVQSNRVFCDTMNSLTLPSEVNLCNVDIFNPKYDCKIMTSKTDVSSSVITSLGAIVSCYGKTKCTASNKNRGIIKTFSNGCDYVSNKGVDTVSVGNTLYYVNKQEGKSLYVKGEPIINFYDPLVFPSDEFDASISQVNEKINQSLAFIRKSDELLSAIGGYIPEAPRDGQAYVRKDGEWVLLSTFLLVPPGSHHHHHH"

def replace_amino_acid2(sequence, position, new_amino_acid):
   
    # 将序列转换为列表，因为字符串是不可变的
    sequence_list = list(sequence)

    # 替换指定位置的氨基酸
    sequence_list[position-1] = new_amino_acid

    # 将列表转换回字符串并返回
    return ''.join(sequence_list)



position_list = [42,67,74,99,169,172,173,200,201,209,213,228,276,305,326,356,380,384,389,402,462,466,477]
new_amino_acid_list = [
    ["A","R","N","C","Q","H","I","L","F","S","T","W","Y","V"],
    ["E","I","L","F","W","Y"],
    ["D","C","Q","E","H","I","L","F","T","Y"],
    ["A","C","Q","G","H","L","F","T","W","Y"],
    ["R","Q","E","H","I","L","F","T","W","Y","V"],
    ["R","S","T"],
    ["A","R","N","D","C","Q","E","H","I","L","K","F","T","W","Y","V"],
    ["A","R","N","C","Q","E","H","I","L","F","S","T","W","Y","V"],
    ["A","R","N","D","C","Q","E","G","H","I","L","F","S","T","W","Y","V"],
    ["A","R","C","Q","E","H","I","L","F","P","T","W","Y","V"],
    ["R"],
    ["A","R","C","Q","E","G","H","I","L","K","F","S","T","W","Y","V"],
    ["A","Q","E","H","I","L","F","W","Y","V"],
    ["M","Y"],
    ["N","D","C","E","H","I","L","F"],
    ["R","N","Q","H","I","L","F","W","Y","V"],
    ["A","R","C","Q","E","H","I","L","F","S","T","W","Y","V"],
    ["R","H","I","T"],
    ["A","R","N","D","C","Q","E","G","H","I","L","K","F","S","T","W","Y","V"],
    ["E","L"],
    ["R","I","L","W"],
    ["A","N","D","C","Q","H","F","W","Y"],
    ["R","Q","H","I","L","W","Y","V"]
]

seq_list = []

for i in range(len(position_list)):
    for k in new_amino_acid_list[i]:
        print(str(position_list[i])+k)
        new_sequence = replace_amino_acid2(SEQ, position_list[i], k)
        seq_list.append(new_sequence)

# 输出所有可能的氨基酸序列
#for new_sequence in seq_list:
#    print(new_sequence)       



seq_list2 = []

for x in seq_list:
    for i in range(len(position_list)):
        for k in new_amino_acid_list[i]:
            #print(str(position_list[i])+k)
            new_sequence = replace_amino_acid2(x, position_list[i], k)
            seq_list2.append(new_sequence)

print(len(seq_list))
print(len(seq_list2))

dic_single = {'single':seq_list}
dic_double = {'double':seq_list2}
df = pd.DataFrame(dic_single)
df2 = pd.DataFrame(dic_double)
# write DataFrame to CSV file
df.to_csv('my_list.csv', index=False)
df2.to_csv('my_list2.csv', index=False)